package rj.cometome;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ConfigurationInfo;
import android.graphics.Color;

public class CtMActivity extends Activity {

	private CtMView mGLView;
	private LocationsHandler mLocHandler;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        if (detectOpenGLES20()){
        	Log.d("GLES20", "Supported");
        } else {
            Log.d("GLES20", "Not Supported");
        }
        
        Utils.setContext(this);
        
        mGLView = new CtMView(this);
        mLocHandler = LocationsHandler.getInstance();
        
        RelativeLayout relative = new RelativeLayout(this);
        
        FrameLayout frame = new FrameLayout(this);
        frame.addView(mGLView);
        
        //DebugView debug = new DebugView(this);
        //Utils.setDebugView(debug);
        
        Button button = new Button(this);
        
        button.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				LocationsHandler locHandler = LocationsHandler.getInstance();
				locHandler.pinLocation();
			}
		});
		
        relative.addView(frame);
        //relative.addView(debug);
        
        setContentView(relative);
    }   
    
    protected void onResume() {
    	super.onResume();
    	mLocHandler.registerListeners();
    }
    
    protected void onPause() {
    	super.onPause();
    	mLocHandler.unregisterListeners();
    }
    
    private boolean detectOpenGLES20() {
        ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        ConfigurationInfo info = am.getDeviceConfigurationInfo();
        
        return (info.reqGlEsVersion >= 0x20000);
    }
}
